package com.example.ten.controller;

import com.example.ten.entity.TreeNode;
import com.example.ten.service.MenuService;
import com.example.ten.util.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: Jyc
 * @classname: MenuController
 * @date: 2023/3/28
 * @time: 21:00
 * @description:
 */
@RestController
@RequestMapping("menu")
public class MenuController extends BaseController {

    @Resource
    private MenuService menuService;

    /**
     * 查询所有
     * @return
     */
    @GetMapping("queryTreeNodeData")
    public Result queryTreeNodeData() {
        return success(menuService.queryTreeNodeData());
    }

    /**
     * 根据用户编号查询  用户编号直接从登录成功的session中获取
     * @return
     */
    @GetMapping("queryTreeNodeByUserId")
    public Result queryTreeNodeByUserId() {
        return success(menuService.queryTreeNodeByUserId());
    }

    /**
     * 添加
     * @param treeNode
     * @return
     */
    @PostMapping("add")  //地址栏中的请求，都是get请求，该请求无法在地址栏进行模拟  如果在地址栏模拟，会出现 HTTP状态 405 - 方法不允许
    public Result add(@RequestBody TreeNode treeNode) {//@RequestBody  把对象以json字符串的格式放入Request对象的Body中传递，get请求是没有body
        return success(menuService.add(treeNode));
    }

    /**
     * 更新
     * @param treeNode
     * @return
     */
    @RequestMapping(value = "update",method = RequestMethod.POST)
    public Object update(@RequestBody TreeNode treeNode) {
        return success(menuService.update(treeNode));
    }

    /**
     * 根据编号删除对象
     * @param menuId
     * @return
     */
    @DeleteMapping("deleteById") //地址栏无法模拟  会报HTTP状态 405 - 方法不允许
    public Object deleteById(Integer menuId) {
        return success(menuService.delete(menuId));
    }
}
